<template>
	<view class="details">
		<!-- <uni-nav-bar title="订单管理" left-icon="left" @clickLeft="navBack" backgroundColor="#2CB9A4" color="#F8F8F8"></uni-nav-bar> -->
		<view class="timeSelect">
			<view class="selectTop" @click="showPop">
				筛选：<view>{{form.start_time||'开始时间'}}</view> <text style="margin: 0 20rpx;">-</text>
				<view>{{form.end_time||'结束时间'}}</view>
			</view>
			<view class="icon">
				<u-icon name="close-circle" color="#505050;" v-if="form.start_time" size="18" @click="closeSel2">
				</u-icon>
				<u-icon name="arrow-down" color="#505050;" v-else size="18" @click="showPop">
				</u-icon>
			</view>
		</view>
		<u-sticky style="background:#fff">
			<view class="tabs">
				<u-tabs :list="tabList" :scrollable='false'  bg-color="#F5F5F5" lineColor="#2CB9A4"
					:current="tabIndex" @change="pickerChange" lineWidth="60" :activeStyle="{
			    color: '#2CB9A4',
			    transform: 'scale(1.05)'
			}"></u-tabs>
			</view>
		</u-sticky>
		<view class="todayInfo" v-if="false">
			<view class="item" v-for="(i,index) in todayList">
				<view class="topName">
					{{i.name}}
				</view>
				<view class="sum">
					<text class="dolar" v-if="i.dolar">￥</text>{{i.num}}
				</view>
			</view>
		</view>
		<view class="listItem y-c" v-for="(i,index) in list" :key="index" @click="goDetails">
			<view class="item_top y-c border">
				<view class="item_top_row x-bc mb-2">
					<view>订单编号：{{i.order_no}}</view>
					<view>+{{i.price}}</view>
				</view>
			</view>
			<view class="item_bot y-c">
				<view class="item_top_row x-bc mb-2 mt-2">
					<view class="next">{{i.createtime}}</view>
					<view>
						{{i.name}}
					</view>
				</view>
			</view>
		</view>
		<view class="noMore" v-if="last_page==form.page&&list.length!=0"
			style="text-align: center;color: #797575;margin-top: 20rpx;padding-bottom: 60rpx;">
			数据加载完成...
		</view>
		<u-empty text="暂无列表哦~~" mode="list" v-if="list.length==0" margin-top='50'></u-empty>
		<lingfeng-timepicker ref="timePop" type="date-range" @change="timeChange"
			:maxDate="maxDate"></lingfeng-timepicker>
	</view>
</template>

<script>
	import {
		orderList,
		census
	} from '@/request/api.js'
	export default {
		data() {
			return {
				minDate: {
					year: 2020,
					month: 3,
					date: 5
				},
				maxDate: {
					year: 2033,
					month: 9,
					date: 20
				},
				form: {
					page: 1,
					day: 0,
					start_time: '',
					end_time: ''
				},
				list: [],
				tabList: [{
					name: '全部'
				}, {
					name: '今日'
				}, {
					name: '本周'
				}, {
					name: '本月'
				}, {
					name: '本年'
				}],
				tabIndex: 0,
				todayList: [{
					name: '今日订单',
					num: '50'
				}, {
					name: '今日营业额',
					num: '50',
					dolar: true
				}, {
					name: '今日收益',
					num: '50',
					dolar: true
				}, {
					name: '累计用户',
					num: '50'
				}]
			};
		},
		onLoad() {
			this.form.page = 1
			this.list = []
			this.form.day = 0
			this.census()
			this.getList()
		},
		onReachBottom() {
			// console.log(111)
			if (this.form.page < this.last_page) {
				this.form.page = this.form.page + 1
				this.getList()
			}
		},
		methods: {
			async census() {
				let res = await census()
				this.todayList[0].num = res.data.today_order
				this.todayList[1].num = res.data.today_turnover
				this.todayList[2].num = res.data.today_income
				this.todayList[3].num = res.data.member_num
				console.log(res, 1111)
			},
			closeSel2() {
				this.form.start_time = ''
				this.form.end_time = ''
				this.form.page = 1
				this.list = []
				this.getList()
			},
			async getList() {
				let res = await orderList(this.form)
				this.list = this.list.concat(res.data.data)
				this.last_page = res.data.last_page
				console.log(res, '订单列表')
			},
			async timeChange(val) {
				console.log(val, 1111);
				this.form.start_time = val[0]
				this.form.end_time = val[1]
				this.form.day = 0
				this.list = []
				this.tabIndex = 0
				this.form.day = 0
				this.getList()
				// let res = await openTime({start_time:val[0],end_time:val[1]});
				// this.defaultData = val;
				// uni.showToast({
				// 	title: '设置成功',
				// 	icon: 'none',
				// 	duration: 1500
				// })
				// console.log(res)
			},
			showPop() {
				this.$refs.timePop.show();
			},
			pickerChange(e) {
				this.tabIndex = e.index
				switch (e.index) {
					case 0:
						this.form.day = e.index
						break;
					case 1:
						this.form.day = e.index
						break;
					case 2:
						this.form.day = e.index
						break;
					case 3:
						this.form.day = e.index
						break;
					case 4:
						this.form.day = e.index
						break;
				}
				this.form.page = 1
				this.form.start_time = ''
				this.form.end_time = ''
				this.list = []
				this.getList()
				console.log(this.form, 111)
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-tabs {
		background: #f5f5f5;
		margin-left: -15rpx;
		margin-right: -15rpx;
	}

	::v-deep .u-sticky {
		z-index: inherit !important;
	}

	.details {
		font-size: 28rpx;
		padding: 0 20rpx 20rpx 20rpx;
		overflow-x: hidden;

		.icon {
			margin-left: 20rpx;
		}

		.timeSelect {
			display: flex;
			align-items: center;
			background: #f5f5f5;
			font-size: 26rpx;
			margin: 0;
			height: 44px;
			margin-left: -20px;
			margin-right: -20px;
			padding: 0 20px;
			position: sticky;
			top: 0;

			.selectTop {
				display: flex;
			}
		}

		.tabs {
			width: 100%;
		}

		.todayInfo {
			display: flex;
			justify-content: space-evenly;
			box-shadow: 0px 0px 10px rgba(8, 23, 56, 0.05);
			border-radius: 8px;
			padding: 20rpx;
			background: #fff;
			margin-top: 30rpx;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.topName {
					color: #1D1B20;
				}

				.sum {
					color: #2CB9A4;
					margin-top: 10rpx;
				}
			}
		}

		.listItem {
			color: $common-color;
			background: #fff;
			border-radius: 20rpx;
			padding: 20rpx;
			box-sizing: border-box;
			margin-top: 20rpx;

			.item_over {
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
			}
		}

		.border {
			border-bottom: 0.5rpx solid rgba(217, 217, 217, 0.6);
		}

		.item_bot {
			.next {
				color: #BABABA;
			}

			.image {
				width: 116rpx;
				height: 100rpx;
			}
		}
	}
</style>